<?php
    class Factory {
        static private $obj = null;
        static public function SetController() {
            $c = self::getC();
             if(in_array($c,array('manager','nav','level'))){
                 if (!isset($_SESSION['admin'])) {
                     Redirect::getInstance()->success('?c=admin&m=login');
                 }
             }
            if(!file_exists(ROOT_PATH.'/controller/'.$c.'Controller.class.php')) $c = 'Index';
            eval('self::$obj = new '.ucfirst($c).'Controller();');
            return self::$obj;
        }
        static public function setModel() {
		    $c = self::getC();
		    if (file_exists(ROOT_PATH.'/model/'.$c.'Model.class.php')) eval('self::$obj = new '.ucfirst($c).'Model();');
		    return self::$obj;
	    }
        static public function getC() {
		    if(isset($_GET['c']) && !empty($_GET['c'])){
                return $_GET['c'];
            }
            return 'Index';
	    }
    }